<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./Public/jquery.11.min.js"></script>
    <script>
        $(function () {
            //异步检测用户名是否存在
            $('input[name=username]').blur(function () {
                var uname = $(this).val();
                $.ajax({
                    url : 'index.php?c=Member&a=checkUser',
                    type:'post',
                    data:{u:uname},
                    success:function(phpData){
                        if(phpData == 1){//如果用户存在
                            $('#userMsg').html('<span style="color: red">用户名存在</span>');
                            $('#sub').attr('disabled',true);
                        }else{
                            $('#userMsg').html('<span style="color: green">可以注册</span>');
                            $('#sub').attr('disabled',false);
                        }
                    }
                })
            })
        })
    </script>
</head>
<body>
注册
<hr>
<form action="" method="post">
    用户名:<input type="text" name="username" id="">
    <span id="userMsg"></span>
    <br>
    密码:<input type="password" name="password" id="">
    <br>
    <img src="?c=Member&a=code" alt="">
    <br>
    验证码:<input type="text" name="code" id="">

    <span id="codeMsg">验证码错误</span>
    <br>
    <input type="submit" value="注册" id="sub">
</form>
</body>
</html>